<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
    function __construct()
    {
      parent::__construct();
      $this->load->model('auth');
    }
   
    public function index()
    {
        $user = $this->session->userdata('user_authentication');

        $data['page_title'] = 'brown';
        $this->load->view('admin/loginadmin',$data);
    }
    
    public function auth() {
        $user   = $this->auth->get_user();
		
        if (!empty($user)) {
            $sessiondata = array(
                'id' => $user->id,
                'id_group' => $user->id_group,
                'id_sekolah' => $user->id_sekolah,
                'username' => $user->username,
                'images' => $user->images
            );
			
            $this->session->set_userdata('user_authentication', $sessiondata);//pr($this->session->userdata);die();
            redirect('admin/');
        } else {
            redirect('/');
        }
    }
    
    public function logout() {
        $this->session->unset_userdata('user_authentication');
		session_destroy();
        redirect('/');
    }
}
?>